package cn.tedu.mall.search.test;

public class zhongjianjiedian {
    public static void main(String[] args) {
        Node head = new Node(1);
        head.next = new Node(2);
        head.next.next = new Node(3);
        head.next.next.next = new Node(4);
        head.next.next.next.next = new Node(5);
        head.next.next.next.next.next = new Node(6);
        head.next.next.next.next.next.next = new Node(7);
        Node zj = zhongJian(head);
        System.out.println(zj.value);
    }

    private static Node zhongJian(Node head) {
        if (head == null){
            return null;
        }
        Node fast = head;
        Node slow = head;
        while (fast != null && fast.next != null){
            fast = fast.next.next;
            slow = slow.next;
        }
        return slow;
    }

    static class Node{
        int value;
        Node prev;
        Node next;

        Node(int value){
            this.value = value;
        }
    }
}
